/**
 * Created by chenmingkang on 16/3/8.
 *
 *  {
 *       name : 路由的名称,
 *       url: 路由的url,
 *
 *       views 里面的参数
 *            uiView : 页面上uiView的名字,嵌套路由或者新路由需要传入
 *            templateUrl : 模版路径,
 *            controller: 控制器
 *       }
 *    }
 */
;(function(app){
    //.state('brandSele', {
    //    url: '/brandSele',   //品牌街
    //    views: {
    //        'appState': {
    //            templateUrl: 'brandSele.html',
    //            controller: "brandSele"
    //        }
    //    }
    //})

    var route = [
        {name : 'index', url: '/index.html',templateUrl:'/admin/view/index/index.html', controller: "indexCtr",activeIndex:1},
        {name : 'adConfig', url: '/adConfig.html',templateUrl:'/admin/view/index/adConfig.html', controller: "adConfigCtr",activeIndex:9},

        {name : 'order/orderList/list', url: '/order/orderList/list.html',templateUrl:'/admin/view/order/orderList/orderList.html', controller: "orderListCtr",activeIndex:2},
        {name : 'order/orderList/detail', url: '/order/orderList/detail.html&{orderNo}',templateUrl:'/admin/view/order/orderList/orderDetail.html', controller: "orderDetailCtr",activeIndex:2},
        {name : 'order/employee/list', url: '/order/employee/list.html',templateUrl:'/admin/view/order/employee/employeeList.html', controller: "employeeListCtr",activeIndex:3},
        {name : 'order/employee/num', url: '/order/employee/employeeNum.html&{id}',templateUrl:'/admin/view/order/employee/employeeNum.html', controller: "employeeNumCtr",activeIndex:3},

        {name : 'goods/goodsList/list', url: '/goods/goodsList/list.html',templateUrl:'/admin/view/goods/goodsList/goodsList.html', controller: "goodsListCtr",activeIndex:4},
        {name : 'goods/goodsList/aEGoods', url: '/goods/goodsList/aEGoods.html&{model}',templateUrl:'/admin/view/goods/goodsList/aEGoods.html', controller: "aEGoodsCtr",activeIndex:4},
        {name : 'goods/freight/list', url: '/goods/freight/list.html',templateUrl:'/admin/view/goods/freight/freightList.html', controller: "freightListCtr",activeIndex:8},
        {name : 'goods/freight/freightAE', url: '/goods/freight/freightAE.html&{id}',templateUrl:'/admin/view/goods/freight/freightAE.html', controller: "freightAECtr",activeIndex:8},

        {name : 'vip/plainVip/list', url: '/vip/plainVip/list.html',templateUrl:'/admin/view/vip/plainVip/plainVipList.html', controller: "plainVipListCtr",activeIndex:5},
        {name : 'vip/plainVip/detail', url: '/vip/plainVip/detail.html&{id}',templateUrl:'/admin/view/vip/plainVip/plainVipDetail.html', controller: "plainVipDetailCtr",activeIndex:5},
        {name : 'vip/distrVipList', url: '/vip/distrVipList.html',templateUrl:'/admin/view/vip/distrVip/distrVipList.html', controller: "distrVipListCtr",activeIndex:6},

        {name : 'withdraw/withdrawList/list', url: '/withdraw/withdrawList/list.html',templateUrl:'/admin/view/withdraw/withdrawList/withdrawList.html', controller: "withdrawListCtr",activeIndex:7},

        {name : 'other/userList/list', url: '/other/userList/list.html',templateUrl:'/admin/view/other/userList/userList.html', controller: "userListCtr",activeIndex:10}
    ];

    app.config(["$stateProvider","$urlRouterProvider","$httpProvider","ChartJsProvider",function($stateProvider, $urlRouterProvider,$httpProvider,ChartJsProvider) {
        ChartJsProvider.setOptions({ colours : [ '#803690', '#00ADF9', '#DCDCDC', '#46BFBD', '#FDB45C', '#949FB1', '#4D5360'] });

        //
        // czContentForConfigProvider.setOptions({
        //     czYieldHideBeforeCallback : function(scope,element){
        //         if(browser.v.zhefengle){
        //             element.remove();
        //         }
        //     }
        // });

        $httpProvider.interceptors.push('authHttpResponseInterceptor');

        //$httpProvider.defaults.withCredentials = true;
        $httpProvider.defaults.headers.put['Content-Type'] = 'application/x-www-form-urlencoded';
        $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
        $httpProvider.defaults.headers.common['Accept'] = 'application/json, text/plain, */*';
        // $httpProvider.defaults.headers.common['PAJAX'] = 'true';
        //$httpProvider.defaults.headers.common['DNT'] = '1';

        $httpProvider.defaults.transformRequest = [function(data) {
            /**
             * The workhorse; converts an object to x-www-form-urlencoded serialization.
             * @param {Object} obj
             * @return {String}
             */
            return angular.isObject(data) && String(data) !== '[object File]' ? angular.param(data) : data;
        }];

        route.forEach(function(item){
            var params = {
                name : item.name,
                url: item.url,
                activeIndex : item.activeIndex,
                views : {}
            };
            params.views[item.uiView || 'appState'] = {
                templateUrl : item.templateUrl,
                controller : item.controller
            };
            $stateProvider.state(params);
        });

        $urlRouterProvider.otherwise(route[0].url);

    }]);
})(app);

